package com.example.leetcode.tree;

import com.example.leetcode.tree.common.TreeNode;
import com.example.leetcode.tree.common.TreeUtils;

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 * int val;
 * TreeNode left;
 * TreeNode right;
 * TreeNode(int x) { val = x; }
 * }
 */
class Solution236 {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        return TreeUtils.lowestCommonAncestor(root, p, q);
    }
}

public class leetcode236 {
    public static void main(String[] args) {
        Solution236 solution236 = new Solution236();
        Integer[] nums = {3, 5, 1, 6, 2, 0, 8, null, null, 7, 4};
        TreeNode root = TreeUtils.generateLeetcodeTree(nums);
        TreeNode p = TreeUtils.getTreeNodeByVal(root, 5);
        TreeNode q = TreeUtils.getTreeNodeByVal(root, 1);
        System.out.println(solution236.lowestCommonAncestor(root, p, q).val);
    }
}
